﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 9/7/2009
 * Time: 6:21 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections.Generic;

namespace Buaya.Model
{
	/// <summary>
	/// Description of Module.
	/// </summary>
	public class Module
	{
		int id;
		IList<ModuleCommand> commands = new List<ModuleCommand>();
		bool inactive;
		int order;
		
		public virtual int Order {
			get { return order; }
			set { order = value; }
		}
		
		public virtual bool Inactive {
			get { return inactive; }
			set { inactive = value; }
		}
		
		public virtual IList<ModuleCommand> Commands {
			get { return commands; }
			set { commands = value; }
		}
		
		public virtual int Id {
			get { return id; }
			set { id = value; }
		}
		string name;
		
		public virtual string Name {
			get { return name; }
			set { name = value; }
		}
		
		public Module()
		{
		}
		
		public virtual void RemoveCommand(ModuleCommand c)
		{
			commands.Remove(c);
			OnCommandAdded(null);
		}
		
		public virtual void AddCommand(string command)
		{
			AddCommand("", command);
		}
		
		public virtual void AddCommand(string name, string command)
		{
			AddCommand(new ModuleCommand(name, command));
		}
		
		public virtual void AddCommand(ModuleCommand command)
		{
			command.Module = this;
			commands.Add(command);
			OnCommandAdded(null);
		}
		
		protected virtual void OnCommandAdded(EventArgs e)
		{
			if (CommandAdded != null) {
				CommandAdded(this, e);
			}
		}
		
		public virtual event EventHandler CommandAdded;
	}
	
	public class ModuleCommand
	{
		Module module;
		
		public virtual Module Module {
			get { return module; }
			set { module = value; }
		}
		int id;
		
		public virtual int Id {
			get { return id; }
			set { id = value; }
		}
		string command;
		
		public virtual string Command {
			get { return command; }
			set { command = value; }
		}
		string name;
		
		public virtual string Name {
			get { return name; }
			set { name = value; }
		}
		
		public ModuleCommand()
		{
		}
		
		public ModuleCommand(string name, string command)
		{
			this.name = name;
			this.command = command;
		}
	}
}
